var labelMap = new Map();
var ipAddress = 'http://192.168.2.41:9000/';
function loadElectricityNet() {

    let normalModelScale = 250;
    let switchModelScale = 150;
    let leftTopline = new GE.FlowLine2({
        positions: [
            new GE.Point(120.21372596415473, 30.339352175005928, 0),
            new GE.Point(120.22335743813406, 30.339352175005928, 0),
            new GE.Point(120.22335743813406, 30.34173103424986, 0),
        ],
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
        // loopMsg: {loopTime: 3, sleepTime: 1000}
    });
    app.add(leftTopline);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/整流器.glb', [120.21372596415473, 30.339352175005928, 0], 'gltf', normalModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/蓄电池.glb', [120.22335743813406, 30.34173103424986, 0], 'gltf', normalModelScale);
    let leftTopLabel0 = new GE.ElectricLabel2({ position: new GE.Point(120.2118, 30.3388, 0), labelValue: '整流器1', realValue: '232.21V', fontColor: '#00FF7F' });
    let leftTopLabel = new GE.ElectricLabel({ position: new GE.Point(120.22555743813406, 30.3404, 0), labelValue: '1段负载', fontColor: '#00BFFF' });
    labelMap.set('整流器1', leftTopLabel0);

    let leftDownLine = new GE.FlowLine2({
        positions: [
            new GE.Point(120.22335743813406, 30.34173103424986, 0),
            new GE.Point(120.22335743813406, 30.32655457108341, 0),
            // new GE.Point(120.270646, 30.38362, 0),
            // new GE.Point(120.17020432419753, 30.38362, 0),
        ],
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
    });
    app.add(leftDownLine);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.22335743813406, 30.334952960452817, 0], 'gltf', switchModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/蓄电池.glb', [120.22335743813406, 30.32655457108341, 0], 'gltf', normalModelScale);
    let leftDownLabel0 = new GE.ElectricLabel2({ position: new GE.Point(120.2252, 30.3342, 0), labelValue: 'K01状态', realValue: '(闭合)', fontColor: '#B22222' });
    let leftDownLabel1 = new GE.ElectricLabel({ position: new GE.Point(120.2234, 30.3240, 0), labelValue: '蓄电池组1', fontColor: '#00BFFF' });
    let leftDownLabe2 = new GE.ElectricLabel({ position: new GE.Point(120.221, 30.3255, 0), labelValue: '(点击查看详情)', fontSize: 30, fontColor: '#00BFFF' });
    let leftDownLabe3 = new GE.ElectricLabel2({ position: new GE.Point(120.2195, 30.3291, 0), labelValue: '组端电流1', realValue: '0.07A', fontColor: '#00FF7F' });
    let leftDownLabe4 = new GE.ElectricLabel2({ position: new GE.Point(120.222, 30.3291, 0), labelValue: '组端电压1', realValue: '232.17V', fontColor: '#00FF7F' });
    labelMap.set('K01状态', leftDownLabel0);
    labelMap.set('组端电流1', leftDownLabe3);
    labelMap.set('组端电压1', leftDownLabe4);

    let rightTop = new GE.FlowLine2({
        positions: [
            new GE.Point(120.25233307083433, 30.339352175005928, 0),
            new GE.Point(120.24352133656865, 30.339352175005928, 0),
            new GE.Point(120.24352133656865, 30.34173103424986, 0),
        ],//, startTime:10000
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
    });
    app.add(rightTop);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/整流器.glb', [120.25233307083433, 30.339352175005928, 0], 'gltf', normalModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/蓄电池.glb', [120.24352133656865, 30.34173103424986, 0], 'gltf', normalModelScale);
    let topMiddleLabel0 = new GE.ElectricLabel2({ position: new GE.Point(120.25233307083433, 30.3375, 0), labelValue: '整流器2', realValue: '232.93V', fontColor: '#00FF7F' });
    let rightTopLabel = new GE.ElectricLabel({ position: new GE.Point(120.241, 30.3403, 0), labelValue: '2段负载' });
    labelMap.set('整流器2', topMiddleLabel0);

    let rightDown = new GE.FlowLine2({
        positions: [
            new GE.Point(120.24352133656865, 30.339352175005928, 0),
            new GE.Point(120.24352133656865, 30.32655457108341, 0),
        ],//, startTime:10000
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
    });
    app.add(rightDown);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.24352133656865, 30.334952960452817, 0], 'gltf', switchModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/蓄电池.glb', [120.24352133656865, 30.32655457108341, 0], 'gltf', normalModelScale);
    let rightDownLabel0 = new GE.ElectricLabel2({ position: new GE.Point(120.245, 30.3342, 0), labelValue: 'K02状态', realValue: '(闭合)', fontColor: '#B22222' });
    let rightDownLabel = new GE.ElectricLabel({ position: new GE.Point(120.2435, 30.3240, 0), labelValue: '蓄电池组2', fontColor: '#00BFFF' });
    let rightDownLabe2 = new GE.ElectricLabel({ position: new GE.Point(120.2465, 30.3255, 0), labelValue: '(点击查看详情)', fontSize: 30, fontColor: '#00BFFF' });
    let rightDownLabel3 = new GE.ElectricLabel2({ position: new GE.Point(120.2450, 30.3291, 0), labelValue: '组端电流2', realValue: '0.32A', fontColor: '#00FF7F' });
    let rightDownLabel4 = new GE.ElectricLabel2({ position: new GE.Point(120.2475, 30.3291, 0), labelValue: '组端电压2', realValue: '233.04V', fontColor: '#00FF7F' });
    labelMap.set('K02状态', rightDownLabel0);
    labelMap.set('组端电流2', rightDownLabel);
    labelMap.set('组端电压2', rightDownLabel4);

    let topMiddle = new GE.FlowLine2({
        positions: [
            new GE.Point(120.22335743813406, 30.339352175005928, 0),
            new GE.Point(120.24352133656865, 30.339352175005928, 0),
        ],//, startTime:10000
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
        isProduct: false
    });
    app.add(topMiddle);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.2333465767982, 30.339352175005928, 0], 'gltf', switchModelScale);
    let topMiddleLabel = new GE.ElectricLabel2({ position: new GE.Point(120.23327405474643, 30.3375, 0), labelValue: '智能母联', realValue: '(断开)', fontColor: '#00FF7F' });
    labelMap.set('智能母联', topMiddleLabel);
    
    let bottomMiddleLine = new GE.FlowLine2({
        positions: [
            new GE.Point(120.22335743813406, 30.33079542141768, 0),
            new GE.Point(120.24352133656865, 30.33079542141768, 0),
        ],//, startTime:10000
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
        isProduct: false
    });
    app.add(bottomMiddleLine);
    let bottomMiddleLabel1 = new GE.ElectricLabel({ position: new GE.Point(120.2310, 30.3340, 0), labelValue: '放电电压', fontColor: '#00BFFF' });
    let bottomMiddleLabel2 = new GE.ElectricLabel({ position: new GE.Point(120.2358, 30.3340, 0), labelValue: '放电电流', fontColor: '#00BFFF' });
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.22746515248741, 30.33079542141768, 0], 'gltf', switchModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.23832331511144, 30.33079542141768, 0], 'gltf', switchModelScale);
    let bottomMiddleLabe1 = new GE.ElectricLabel2({ position: new GE.Point(120.2275, 30.3291, 0), labelValue: '充放电开关K1', realValue: '(断开)', fontColor: '#00FF7F' });
    let bottomMiddleLabe2 = new GE.ElectricLabel2({ position: new GE.Point(120.2385, 30.3291, 0), labelValue: '充放电开关K2', realValue: '(断开)', fontColor: '#00FF7F' });
    let bottomMiddleLabe3 = new GE.ElectricLabel3({ position: new GE.Point(120.2365, 30.3261, 0), fontColor: '#00FF7F' });
    labelMap.set('充放电开关K1', bottomMiddleLabe1);
    labelMap.set('充放电开关K2', bottomMiddleLabe2);
    labelMap.set('交流电网', bottomMiddleLabe3);

    let bottomMiddleDonwLine = new GE.FlowLine2({
        positions: [
            new GE.Point(120.2333465767982, 30.33079542141768, 0),
            new GE.Point(120.2333465767982, 30.32655457108341, 0),
        ],//, startTime:10000
        lineColor: '#1E90FF',
        startColor: '#1E90FF',
        endColor: '#AFEEEE',
        spaceDistance: 10,
        narrowLength: 40,
        waitTime: 3,
        isProduct: false
    });
    app.add(bottomMiddleDonwLine);
    let bottomMiddleDonwLabel1 = new GE.ElectricLabel({ position: new GE.Point(120.2332, 30.3308, 0), labelValue: '双向换流器', fontColor: '#00BFFF' });
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/双向整流器.glb', [120.2333465767982, 30.33079542141768, 0], 'gltf', normalModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/开关2.glb', [120.2333465767982, 30.32871825614352, 0], 'gltf', switchModelScale);
    this.loadModel(ipAddress + 'examples/resources/gltf/eletricTest/蓄电池.glb', [120.2333465767982, 30.326554571083, 0], 'gltf', normalModelScale);
    let bottomMiddleDonwLabel2 = new GE.ElectricLabel({ position: new GE.Point(120.2335, 30.3240, 0), labelValue: '交流电网', fontColor: '#00BFFF' });

}

function loadModel(url, position, type, scale) {
    model = new GE.OverLay({
        type: type,
        url: url,
        dracoPluginUrl: ipAddress + 'examples/resources/plugin/draco/',
        // mtlUrl: extraUrl,
        // url: 'http://localhost:9000/examples/resources/fbx/ceshi1.FBX',
        // url:'http://192.168.2.43:9000/examples/resources/fbx/box.gltf',
        position: position, //[122.00151626214978, 40.71106690828059, 20.0],
        changeEmissive: false,
        gltfUpAxis: 'Z',
        // gltfUpAxis: 'Y',
        scale: [scale, scale, scale],
        // rotation: [90, 0, 0],
        // isUseContourLine: true, //是否使用等高线
        success: function (fbxParent) {

        }
    })
    app.add(model);


    window.model = model;
}

function setValue(key, value) {
    let label = labelMap.get(key);
    if (!label) {
        return;
    }

    if(label instanceof GE.ElectricLabel2){
        label.updateContent({realValue: value});
    }
    if(label instanceof GE.ElectricLabel3){
        label.updateContent(value);
    }
}